import Taro from '@tarojs/taro'

import { SWITCH_TAB } from '../constants'

const tabbar_lists = Taro.getApp().config.tabBar.list;

export const actions = {
  onSwitchTab: (index) => {
    const item = tabbar_lists[index];
    if (process.env.TARO_ENV === 'h5') {
      Taro.redirectTo({
        url: item.pagePath
      });
    } else {
      Taro.switchTab({
        url: '../../' + item.pagePath
      });
    }
    return {
      type: SWITCH_TAB,
      pageIndex: index
    }
  }
}

export default {
  actions
};
